<html>
<head><meta charset="utf-8"><title>inline(never) on default methods doesn&#x27;t work? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/inline(never).20on.20default.20methods.20doesn&#x27;t.20work.3F.html">inline(never) on default methods doesn&#x27;t work?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="228624484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/inline%28never%29%20on%20default%20methods%20doesn%27t%20work%3F/near/228624484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/inline(never).20on.20default.20methods.20doesn&#x27;t.20work.3F.html#228624484">(Mar 03 2021 at 16:43)</a>:</h4>
<p>In core's <code>Write</code> trait I tried adding a <code>inline(never)</code> to <code>write_fmt</code>:</p>
<div class="codehilite"><pre><span></span><code>pub trait Write {
    ...

    #[inline(never)]
    fn write_fmt(mut self: &amp;mut Self, args: Arguments&lt;&#39;_&gt;) -&gt; Result {
        write(&amp;mut self, args)
    }
}
</code></pre></div>
<p>My expectation was, every implementation of this trait without a <code>write_fmt</code> would get the default <code>write_fmt</code>, including the <code>inline(never)</code> attribute.</p>
<p>However in practice that does not happen, the methods are still inlined. If I really want to not inline this I have to override it in implementations and add <code>inline(never)</code> there. For example, in <code>String</code>:</p>
<div class="codehilite"><pre><span></span><code>impl fmt::Write for String {
    ...

    #[inline(never)]
    fn write_fmt(mut self: &amp;mut Self, args: fmt::Arguments&lt;&#39;_&gt;) -&gt; fmt::Result {
        fmt::write(&amp;mut self, args)
    }
}
</code></pre></div>
<p>Is this working as expected, or a bug? Is this documented somewhere?</p>



<a name="228624588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/inline%28never%29%20on%20default%20methods%20doesn%27t%20work%3F/near/228624588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/inline(never).20on.20default.20methods.20doesn&#x27;t.20work.3F.html#228624588">(Mar 03 2021 at 16:44)</a>:</h4>
<p>I think this is a bug personally</p>



<a name="228647196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/inline%28never%29%20on%20default%20methods%20doesn%27t%20work%3F/near/228647196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/inline(never).20on.20default.20methods.20doesn&#x27;t.20work.3F.html#228647196">(Mar 03 2021 at 18:58)</a>:</h4>
<p>OK thanks. I'll submit an issue.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>